/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javabahia.dao;

import java.util.List;
import javabahia.bean.Person;
import org.easycassandra.persistence.EasyCassandraManager;
import org.easycassandra.persistence.Persistence;

/**
 *
 * @author otavio - otaviojava@java.net
 */
public class PersonDAO implements CRUD<Person> {

    private static final long serialVersionUID = 1L;
    
    /**
     * The Manager Object
     */
    private Persistence persistence;

    public PersonDAO() {
        /*paramether: 
         * name of KeyStore
         * the host
         * number of the port
         */
        persistence = EasyCassandraManager.getPersistence("javabahia", "localhost", 9160);
    }

    public void create(Person bean) {
        
            //you can also inform the level's consistency
            //fo example
            //persistence.insert(bean, ConsistencyLevel.ALL);
            persistence.insert(bean);
        
    }

    public void remove(Person bean) {
       
        
        persistence.delete(bean);
    }

    public void remove(Long id){
        
     
        persistence.deleteByKeyValue(id, Person.class);
    
    }
    
    public void update(Person bean) {

        //you can also inform the level's consistency
        // for example
        //  persistence.update(bean, ConsistencyLevelCQL.ALL);
        persistence.update(bean);

    }

    public Person retrieve(Object id) {
      
            // you can also inform the level's consistency
            // for example
            // persistence.findByKey(id, Person.class, ConsistencyLevelCQL.ALL);

            return (Person) persistence.findByKey(id, Person.class);
      
        
    }

    @SuppressWarnings("unchecked")
    public List<Person> listAll() {
      
            //you can also inform the level's consistency
            //The default size is 10000
//            persistence.findAll(Person.class, ConsistencyLevelCQL.ALL);
//            persistence.findAll(Person.class, 30000);
//            persistence.findAll(Person.class,ConsistencyLevelCQL.ALL ,30000);
            return persistence.findAll(Person.class);
      
    }

    @SuppressWarnings("unchecked")
    public List<Person> listByIndex(Object index) {
      
            return persistence.findByIndex(index, Person.class);
      
    }

   
}
